if (WIN32)
  if (NOT BUILD_SHARED_LIBS)
    add_definitions (-DBOBS_STATIC)
  endif (NOT BUILD_SHARED_LIBS)
endif (WIN32)

set (SOURCES test.cpp)

add_executable (cppunit_test ${SOURCES})
target_link_libraries (cppunit_test bobs-services debug ${CPPUNIT_DEBUG_LIBRARIES} optimized ${CPPUNIT_LIBRARIES})

# Create ctests and set its environment variables
if (WIN32)
  
  # Set variables with executable and library paths depending on the build configuration
  get_target_property (bobs-services_debug bobs-services LOCATION_Debug)
  get_filename_component (bobs-services_debug ${bobs-services_debug} PATH)
  get_filename_component (cppunit_lib_debug ${CPPUNIT_DEBUG_LIBRARIES} PATH)

  get_target_property (bobs-services_release bobs-services LOCATION_Release)
  get_filename_component (bobs-services_release ${bobs-services_release} PATH)
  get_filename_component (cppunit_lib_release ${CPPUNIT_LIBRARIES} PATH)

  #
  # IMPORTANT NOTE: The set_tests_properties(), below, internally
  # stores its name/value pairs with a semicolon delimiter.
  # because of this we must protect the semicolons in the path
  #
  set (LD_VARNAME "PATH")
  set (LD_PATH_Debug "${bobs-services_debug}\\;${cppunit_lib_debug}\\;${Boost_LIBRARY_DIRS}")
  set (LD_PATH_Release "${bobs-services_release}\\;${cppunit_lib_release}\\;${Boost_LIBRARY_DIRS}")

  add_test (NAME CppUnitTestDebug CONFIGURATIONS Debug COMMAND cppunit_test)
  set_property (TEST CppUnitTestDebug PROPERTY ENVIRONMENT "${LD_VARNAME}=${LD_PATH_Debug}")
  
  add_test (NAME CppUnitTestRelease CONFIGURATIONS Release COMMAND cppunit_test)
  set_property (TEST CppUnitTestRelease PROPERTY ENVIRONMENT "${LD_VARNAME}=${LD_PATH_Release}")
  
else (WIN32)

  get_target_property (bobs-services_path bobs-services LOCATION)
  get_filename_component (bobs-services_path ${bobs-services_path} PATH)

  # Set variable with library paths depending on the build configuration
  if (CMAKE_BUILD_TYPE MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
    get_filename_component (cppunit_lib_path ${CPPUNIT_DEBUG_LIBRARIES} PATH)
  else ()
    get_filename_component (cppunit_lib_path ${CPPUNIT_LIBRARIES} PATH)
  endif ()
  
  set (LD_VARNAME "LD_LIBRARY_PATH")
  set (LD_PATH "${bobs-services_path}:${cppunit_lib_path}:${Boost_LIBRARY_DIRS}")

  add_test (NAME CppUnitTest COMMAND cppunit_test)
  set_property (TEST CppUnitTest PROPERTY ENVIRONMENT "${LD_VARNAME}=${LD_PATH}")
endif (WIN32)
